package org.example;

import java.util.ArrayList;
import java.util.List;

public class Test3 {
    //leetcode 17 电话号码的字母组合 https://leetcode.cn/problems/letter-combinations-of-a-phone-number/description/
    String[] hash = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> ret;
    public StringBuilder sb;
    public int size;
    public List<String> letterCombinations(String digits) {
        ret = new ArrayList<>();
        sb = new StringBuilder();
        size = digits.length();
        if (digits == null || size == 0) return ret;
        backtracking(digits,0);
        return ret;
    }

    public void backtracking(String digits,int start) {
        if (sb.length() == size) {
            ret.add(sb.toString());
            return;
        }
        String s = hash[digits.charAt(start) - '0'];
        for (int i = 0; i < s.length(); i++) {
            sb.append(s.charAt(i));
            backtracking(digits,start + 1);
            sb.deleteCharAt(sb.length() - 1);
        }
    }

    public static void main(String[] args) {
        Test3 test3 = new Test3();
        test3.letterCombinations("7");
        System.out.println(777);
    }
}
